package com.itheima;

import com.alibaba.druid.pool.DruidDataSource;
import com.itheima.dao.BookDao;
import com.mchange.v2.c3p0.ComboPooledDataSource;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import javax.sql.DataSource;
import java.beans.PropertyVetoException;
import java.sql.Connection;
import java.sql.SQLException;


public class App {
    public static void main( String[] args ) throws PropertyVetoException, SQLException {

    /*    DruidDataSource dds=new DruidDataSource();
        dds.setDriverClassName("com.mysql.jdbc.Driver");
        dds.setUsername("root");
        dds.setPassword("root");
        dds.setUrl("jdbc:mysql://localhost:3306/spring_db");
        Connection connection = dds.getConnection();
        System.out.println(connection);


        ComboPooledDataSource cpd=new ComboPooledDataSource();
        cpd.setDriverClass("com.mysql.jdbc.Driver");
        cpd.setUser("root");
        cpd.setPassword("root");
        cpd.setJdbcUrl("jdbc:mysql://localhost:3306/spring_db");
        System.out.println(cpd.getConnection());
*/

        ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
        DataSource dataSource = (DataSource) ctx.getBean("dataSource");
        System.out.println(dataSource);

        BookDao bookDao = (BookDao) ctx.getBean("bookDao");
        bookDao.save();
    }
}
